package com.main.tripplanner.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.main.tripplanner.persistent.Country;
import com.main.tripplanner.persistent.Route;

@Repository
public class RouteDAO extends AbstractDAO{

	@Autowired
	private DosageDAO dosageDAO;

	public Route getRouteByCountry(Country country) {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Route.class);
		criteria.add(Restrictions.eq("country", country));
		List<Route> routeList = criteria.list();
		if(routeList.size() == 0){
			return null;
		}
		else{
			return routeList.get(0);
		}
	}

	public Route getFullyInitializedRoute(int routeId) {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Route.class);
		criteria.add(Restrictions.eq("id", routeId));
		criteria.setFetchMode("cities", FetchMode.JOIN);
		criteria.setFetchMode("attractions", FetchMode.JOIN);
		List<Route> list = criteria.list();
		if(list.size() == 0){
			return null;
		}
		else{
			return list.get(0);
		}
	}
}
